import Foundation

public struct PushTime: RawRepresentable {
    public let hour: Int
    public let minute: Int
    
    public var date: Date? {
        var calendar = Calendar.current
        calendar.timeZone = TimeZone.current
        calendar.locale = Locale.current
        return calendar.date(bySettingHour: hour, minute: minute, second: 0, of: Date())
    }
    
    public var rawValue: String {
        String(format: "%02zi:%02zi", hour, minute)
    }
    
    public init(hour: Int = 10, minute: Int = 0) {
        self.hour = hour
        self.minute = minute
    }
    
    public init?(rawValue: String) {
        let arr = rawValue.components(separatedBy: ":")
        if arr.count == 2 {
            hour = Int(arr[0]) ?? 10
            minute = Int(arr[1]) ?? 0
        } else {
            hour = 10
            minute = 0
        }
    }
}
